package com.example.robertluozizhao.java.design.single;

/**
 * Created by Lzz on 8/22/2019.
 */

public class SingleLazyClass {
    private static SingleLazyClass instance; //1.声明静态变量

    private SingleLazyClass(){//2.私有构造
    }

    //3.提供获取单例实例方法
    private SingleLazyClass getInstance(){
        /*******防止多线程并发******/
        if (instance==null) {
            synchronized (SingleLazyClass.class){
                if (instance==null) {
                    instance = new SingleLazyClass();
                }
            }
        }
        return instance;
    }

}



